package com.situ.mall.controller.back;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Category;
import com.situ.mall.entity.Product;
import com.situ.mall.service.IProductService;

@Controller
@RequestMapping(value="/product")
public class BackProductController {
	@Autowired
	private IProductService productService;

	@RequestMapping(value="/getProductListPage")
	public String getProductListPage() {
		return "product_list";
	}
	
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList() {
		return productService.list();
	}
	
	@RequestMapping(value="/getProductInsertPage")
	public String getProductInsertPage() {
		return "product_insert";
	}
	
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Product product) {
		return productService.insert(product);
	}
	
	@RequestMapping(value="/getProductUpdatePage")
	public String getProductUpdatePage(Integer  productId, Model model) {
		List<Category> topCategoryList = new ArrayList<>();
		//Product product = productService.selectById(productId);
		//Integer parentCategoryId = categoryService.getParentCategoryId(categoryId);
		//List<Category> secondCategoryList =  categoryService.selectSecondCategory(parentCategoryId);
		
		//model.addAttribute("topCategoryList", topCategoryList);
		//model.addAttribute("categoryId", product.getCategoryId);
		//model.addAttribute("parentCategoryId", parentCategoryId)
		//model.addAttribute("secondCategoryList", secondCategoryList);		
		
		return "product_update";
	}
	
	
	@RequestMapping(value="/exportExcel")
	public void exportExcel(HttpServletResponse response) {
		productService.exportExcel(response);
	}
}
